<?php

/*
 * File  : aksi_berita.php
 * Table : beritas, kategoris
 */
session_start();
//cek session

if (!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

include "../../../library/fungsi.lib.php";

$module = $_GET["module"];
$opr = $_GET["opr"];

// hapus berita
if ($module == 'berita' AND $opr == 'hapus') {
    $gambar_berita = get_berita_gambar($_GET["id"]);

    mysql_query("DELETE FROM beritas WHERE berita_id='" . $_GET["id"] . "'");
    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);

// input berita
} elseif ($module == 'berita' AND $opr == 'input') {
    $berita_judul = $_POST["in_berita_judul"];
    $berita_kategori_id = $_POST["in_berita_kategori_id"];
    $berita_seo = seo_title($_POST["in_berita_judul"]);
    $berita_isi = $_POST["in_berita_isi"];
    $berita_tgl = $tgl_db;

    $sql = "INSERT INTO beritas(berita_judul,
                                    berita_seo,
                                    berita_kategori_id,
                                    berita_isi,
                                    berita_tgl) 
                            VALUES('$berita_judul',
                                   '$berita_seo',
                                   '$berita_kategori_id',
                                   '$berita_isi',
                                   '$berita_tgl')";

    //echo $sql;
    mysql_query($sql);
    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}

// update berita
elseif ($module == 'berita' AND $opr == 'update') {
    $berita_judul = $_POST["in_berita_judul"];
    $berita_kategori_id = $_POST["in_berita_kategori_id"];
    $berita_seo = seo_title($_POST["in_berita_judul"]);
    $berita_isi = $_POST["in_berita_isi"];
    $berita_tgl = $tgl_db;
    $berita_id = $_POST["id"];

    $sql = "UPDATE beritas SET  berita_judul='$berita_judul',
                                berita_seo='$berita_seo',
                                berita_kategori_id='$berita_kategori_id',
                                berita_isi='$berita_isi',
                                berita_tgl='$berita_tgl'
                WHERE berita_id='$berita_id'";

    //echo $sql;
    mysql_query($sql);
    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}
?>
